package com.zetian.learned.video;

/**
 * Description   问题程序
 *
 * @author Zetian Wang
 * @date 2019/09/20
 **/
public class Array {
    public static void main(String[] args) {
        final double STARTRATE = 10;
        final int NRATES = 6;
        final int NYEARS = 10;
        /**
         * 设定利率操作
         */
        double[] interestRate = new double[NRATES];
        for (int j = 0; j < interestRate.length; j++) {
            interestRate[j] = (STARTRATE + j) / 100.0;
        }
        /**
         * 设置初始余额为10000
         */
        double[][] balances = new double[NYEARS][NRATES];
        for (int j = 0; j < balances[0].length; j++) {
            balances[0][j] = 10000;
        }
        /**
         * 计算未来的利息
         */
        for (int i = 1; i < balances.length; i++) {
            for (int j = 0; j < balances[i].length; j++) {
                double oldBalance = balances[i - 1][j];
                /**
                 * 计算利息
                 */
                double interest = oldBalance * interestRate[j];
                /**
                 * 计算这一年的余额
                 */
                balances[i][j] = oldBalance + interest;
            }
        }
        /**
         * 打印出每次的利率
         */
        for (int j = 0; j < interestRate.length; j++) {
            System.out.printf("%9.0f%%", 100 * interestRate[j]);
            System.out.println();
        }
        /**
         * 打印余额表
         */
        for (double[] row : balances) {
            for (double b : row) {
                System.out.printf("%10.2f", b);
                System.out.println();
            }
        }
    }
}
